package br.usp.ime.origami.foldcut.util;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import br.usp.ime.origami.foldcut.packing.Disk;
import br.usp.ime.origami.foldcut.structures.simplegraph.Vertex;
import br.usp.ime.origami.foldcut.structures.winged.WingedEdge;
import br.usp.ime.origami.foldcut.structures.winged.WingedFace;
import br.usp.ime.origami.foldcut.structures.winged.WingedVertex;

public class TriangleFolderTest extends TestCase
{

	public void testSimpleTriangle() throws FileNotFoundException
	{
		List<WingedVertex> vertices = new ArrayList<WingedVertex>();
		vertices.add(new WingedVertex(0, 0));
		vertices.add(new WingedVertex(1, 0));
		vertices.add(new WingedVertex(2, 0));
		vertices.add(new WingedVertex(1.5, 1.5));
		vertices.add(new WingedVertex(1, 1));
		vertices.add(new WingedVertex(0.5, 0.5));

		List<WingedEdge> edges = new ArrayList<WingedEdge>();
		for (int i = 0; i < 6; i++)
		{
			edges.add(new WingedEdge(vertices.get(i), vertices.get((i + 1) % 6)));
		}
		WingedFace internalFace = new WingedFace(edges.get(0));
		WingedFace externalFace = new WingedFace(edges.get(0));
		
		Vertex v = new Vertex(0,0);
		Disk[] disks = {new Disk(v, 1),new Disk(v, 2),new Disk(v, 3)};
		
		for (int i = 0; i < 6; i++)
		{
			edges.get(i).setCoveringDisk(disks[i/2%3]);
			edges.get(i).setCw(internalFace);
			edges.get(i).setCcw(externalFace);
			edges.get(i).setNextCcw(edges.get((i + 1) % 6));
			edges.get(i).setNextCw(edges.get((i + 1) % 6));
			edges.get(i).setPreviousCcw(edges.get((i - 1 + 6) % 6));
			edges.get(i).setPreviousCcw(edges.get((i - 1 + 6) % 6));
		}

		TriangleFolder tf = new TriangleFolder();
		Molecule m = tf.foldTriangle(internalFace);
		
		System.out.println(internalFace.inSequence());
		System.out.println(externalFace.inSequence());
		
		assertEquals(6, m.getFixeds().size());
		assertEquals(3, m.getTangents().size());
		assertEquals(3, m.getBissectors().size());

	}
}
